package com.syp.auth.dao.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.syp.auth.dao.po.AppMemberEntity;

@Repository
public interface AppMemberRepository extends JpaRepository<AppMemberEntity, Long>, JpaSpecificationExecutor<AppMemberEntity> {

	/**
	 * 根据应用ID获取应用成员
	 * 
	 * @param appId
	 * @return
	 */
	public List<AppMemberEntity> getByAppId(@Param("appId") Long appId);

	/**
	 * 根据应用编码获取应用成员
	 * 
	 * @param appCode
	 * @return
	 */
	public List<AppMemberEntity> getByAppCode(@Param("appCode") String appCode);

	/**
	 * 根据用户ID获取应用成员
	 * 
	 * @param userId
	 * @return
	 */
	public List<AppMemberEntity> getByUserId(@Param("userId") Long userId);

	/**
	 * 根据用编码获取应用成员
	 * 
	 * @param userCode
	 * @return
	 */
	public List<AppMemberEntity> getByUserCode(@Param("userCode") String userCode);

	/**
	 * 根据应用ID批量删除
	 * 
	 * @param appId
	 * @return
	 */
	@Query("DELETE AppMemberEntity WHERE appId=:appId")
	@Modifying
	public Integer deleteBatchByAppId(@Param("appId") Long appId);

	/**
	 * 根据应用ID批量删除
	 * 
	 * @param appId
	 * @return
	 */
	@Query("DELETE AppMemberEntity WHERE appId in(:appIdList)")
	@Modifying
	public Integer deleteBatchByAppIdList(@Param("appIdList") List<Long> appIdList);

	/**
	 * 根据用户ID批量删除
	 * 
	 * @param userId
	 * @return
	 */
	@Query("DELETE AppMemberEntity WHERE userId=:userId")
	@Modifying
	public Integer deleteBatchByUserId(@Param("userId") Long userId);
}
